<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import rollInfo from '@/api/roll/rollInfo'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  rollInfo.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  rollInfo.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'roll_info',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: rollInfo.getList,
  recycleApi: rollInfo.getRecycleList,
  add: {
    show: true,
    api: rollInfo.save,
    auth: ['roll:info:save']
  },
  edit: {
    show: true,
    api: rollInfo.update,
    auth: ['roll:info:update']
  },
  delete: {
    show: true,
    api: rollInfo.deletes,
    auth: ['roll:info:delete'],
    realApi: rollInfo.realDeletes,
    realAuth: ['roll:info:realDeletes']
  },
  recovery: {
    show: true,
    api: rollInfo.recoverys,
    auth: ['roll:info:recovery']
  },
  import: {
    show: true,
    url: 'roll/info/import',
    templateUrl: 'roll/info/downloadTemplate',
    auth: ['roll:info:import']
  },
  export: {
    show: true,
    url: 'roll/info/export',
    auth: ['roll:info:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "房间名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入房间名称"
    }
  },

  {
    title: "房间图片",
    dataIndex: "img",
    formType: "upload",
    returnType: "url",
    search: false,
    type: "image",
    onlyData: true
  },
  {
    title: "房间类型",
    dataIndex: "type",
    formType: "radio",
    dict: {
      name: "roll_info_type",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    },
    search: true,
    commonRules: {
      required: true,
      message: "请输入房间类型  1：主播   2：官方"
    },
    onControl: (val, maFormObject) => {
      const service = maFormObject.getColumnService()
      if (val == 1) {
        service.get('mobile').setAttr('display', true)
      }else {
        service.get('mobile').setAttr('display', false)
      }
    },
    addDefaultValue: '1',
  },
  {
    title: "手机号",
    dataIndex: "mobile",
    labelWidth: '140px',
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入房间类型"
    },
    width:140,
    search:true
  },
  {
    title: "房间口令",
    dataIndex: "secret_signal",
    labelWidth: '140px',
    formType: "input"
  },
  {
    title: "满足充值金额",
    dataIndex: "recharge_money",
    labelWidth: '140px',
    formType: "input-number",
    commonRules: {
      required: true,
      message: "请输入满足充值金额"
    }
  },
  {
    title: "充值开始时间",
    dataIndex: "recharge_start_time",
    labelWidth: '140px',
    formType: "date",
    commonRules: {
      required: true,
      message: "请输入用户可以进入房间的初始时间"
    },
    showTime: true,
    range: false,
  },
  {
    title: "充值结束时间",
    dataIndex: "recharge_end_time",
    labelWidth: '140px',
    formType: "date",
    commonRules: {
      required: true,
      message: "请输入用户可以进入房间的初始时间"
    },
    showTime: true,
    range: false,
  },
  {
    title: "目前房间人数",
    dataIndex: "num_people",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
  },

  {
    title: "初始时间",
    dataIndex: "start_time",
    labelWidth: '140px',
    formType: "date",
    commonRules: {
      required: true,
      message: "请输入用户初始时间"
    },
    showTime: true,
    range: false,
  },
  {
    title: "结束时间",
    dataIndex: "end_time",
    labelWidth: '140px',
    formType: "date",
    commonRules: {
      required: true,
      message: "请输入用户可以进入房间的初始时间"
    },
    showTime: true,
    range: false,
  },
  {
    title: "开奖截止时间",
    dataIndex: "award_time",
    labelWidth: '140px',
    formType: "date",
    commonRules: {
      required: true,
      message: "请输入用户可以进入房间的初始时间"
    },
    showTime: true,
    range: false,
  },
  {
    title: "排序",
    dataIndex: "sort_id",
    labelWidth: '140px',
    formType: "input-number"
  },
  {
    title: "房间状态",
    dataIndex: "status",
    labelWidth: '140px',
    formType: "radio",
    dict: {
      name: "roll_info_status",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    },
    addDefaultValue: '1',
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入创建者"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'roll:info' } </script>